cc.Class({
    extends: cc.Component,

    editor: {
        executeInEditMode: true,//编辑器里运行脚本代码
        disallowMultiple: false,
        menu: "自动摆放位置",
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.setImg();
    },
    setImg(){
        navigator.clipboard.readText().then(text => {
            cc.log(text);
            let arr;

            try {
                arr = JSON.parse(text);
            } catch (error) {
                cc.log('json化失败',error);
                this.destroy();
                return;
            }

            this.node.removeAllChildren();
            for (let i = 0; i < arr.length; i++) {
                const element = arr[i];
                let tnode = new cc.Node(element.name);
                tnode.addComponent(cc.Sprite);
                tnode.x = element.x;
                tnode.y = element.y;
                this.node.addChild(tnode);
            }
            this.destroy();
        });

	}

    // update (dt) {},
});
